package cc.linker.steplink.crm.merchanth5.mq.listener;

import cc.linker.steplink.crm.merchanth5.dao.CSDao;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 获取IDP客服会话数据
 * @Author: whf
 * @Date: 2020年2月26日16:48:16
 * @Version:
 */
@Slf4j
@Component
public class IDPSessionHistoryReceiver {

    @Autowired
    private CSDao csDao;

    /**
     * @Description: 获取IDP客服会话数据
     * @Param:
     * @Return: void
     * @Author: whf
     * @Date: 2020年2月26日16:48:16
     * @Version:
     */
//    @RabbitListener(queues = QueueName.IDP_SESSION_CONTENT)
    public void direct(JSONObject msg) {
        try {
            LOGGER.info("从mq接收IDP会话记录数据：" + msg);
            Map<String,Object> params = new HashMap<>();
            params.put("sessionId",msg.get("sessionId"));
            csDao.updateIDPSession(params);
            List<Map> msgList = JSONObject.parseArray(msg.getString("msgArray"), Map.class);
            if(msgList!=null&&msgList.size()>0){
                params.put("msgList",msgList);
                csDao.addIDPSessionDetail(params);
            }
        } catch (Exception e) {
            LOGGER.error("mq数据错误");
            return;
        }
    }

}
